package com.example.xss.commom.result;

import cn.hutool.http.HttpStatus;
import com.example.xss.commom.enums.IError;
import lombok.Data;

/**
 * tongyongfanhuizhi$
 *
 * @author WANGJIET24
 * @date 2021-6-8$
 */
@Data
public class R<T> {

    private Integer code;

    private T data;

    private String message;

    /**
     * 构建一个返回值
     */
    public static <T> R<T> ok(T data) {
        R<T> tr = new R<>();
        tr.setCode(HttpStatus.HTTP_OK);
        tr.setData(data);
        return tr;
    }
    /**
     * 构建一个返回值
     */
    public static R<Void> error(IError error) {
        R<Void> tr = new R<>();
        tr.setCode(error.getCode());
        tr.setMessage(error.getMessage());
        return tr;
    }
    /**
     * 构建一个返回值
     */
    public static R<Void> error(Integer code,String message) {
        R<Void> tr = new R<>();
        tr.setCode(code);
        tr.setMessage(message);
        return tr;
    }
}
